<?php 
/*************************************************************************************
 * editpoint.php
 * -----------
 * phpGMapTrips 
 * 
 * This php application allows you to easily record your travel destinations 
 * and display them with Google maps.
 * 
 * Author: Stephane Coste (lescoste@gmail.com)
 * Copyright: (c) 2006 Stephane Coste (http://lescoste.net/)
 * Release Version: 0.1
 * CVS Revision Version: $Revision: 1.15 $
 * Date Started: 2006/02/19
 * Last Modified: $Date: 2007/03/08 20:44:29 $
 *
 *************************************************************************************
 *
 *     This file is part of phpGMapTrips.
 *
 *   phpGMapTrips is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   phpGMapTrips is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with phpGMapTrips; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ************************************************************************************/
?>
<?PHP
include_once("secure.php");
/*
edite un point
*/
$file = urldecode($_GET["file"]);
$showpoint = urldecode($_GET["showpoint"]);
$showtrip = urldecode($_GET["showtrip"]);
$lat = urldecode($_GET["lat"]);
$lng = urldecode($_GET["lng"]);

include_once("dbaccess.php");
$triparray = getTripSummary();
$pointarray = getTripPoints($showtrip);

?>
<html>
<head>
<link rel="stylesheet" href="gearth.css" type="text/css" media="screen" />
<style>
body {
	background-color:white;
	font-size:xx-small;
	padding:0;
}
#buttons {
	padding:0;
	position:fixed;
	bottom:0;
	right:0;
	z-index:100;
}
#edittable {
   height:85%;
overflow:auto;
}
</style>
<script>
function deletePoint() {
   if (confirm("<?php echo $lang_alert_delete_control; ?> '"+document.formeditpoints.editNewname.value+"' ?")) {
      document.formeditpoints.editNewname.value = "";
      document.formeditpoints.submit();
   } 
}
function checkValues(aform) {
   if (aform.editTags.value == "") {
      alert('<?php echo $lang_alert_trips_control; ?>');
      return false;
   }
   return true;
}
function hideMe() {
	parent.editMode =false;
	parent.toggleEditPoint("<?php echo $showpoint; ?>");
}
</script>
</head>
<body>
<?php
// load tag list
$triparraySelect = "";
ksort($triparray);
reset($triparray);
$triparraySelect .= "<option value=''>".$lang_select_trip."</option>";
foreach ($triparray as $tagname => $tag) {
	$triparraySelect .= "<option value='".$tagname."'>".$tagname."</option>";
}
?>
<form method="post" action="doeditpoint.php" name="formeditpoints" onsubmit="return(checkValues(this));">

<div id="buttons">
<a href='javascript:void(0);' onclick='deletePoint();' title='<?php echo $lang_delete_place_link; ?>' ><img src='images/trash.gif' alt='<?php echo $lang_delete_place_link; ?>' border=0 /></a>
<input type="button" name="docancel" value="<?php echo $lang_cancel_button; ?>" onclick="hideMe()"> 
<input type="submit" name="doedit" value="<?php echo $lang_save_button; ?>"> 
</div>

<input type='hidden' name='showtrip' value='<?php echo $showtrip; ?>' >
<input type='hidden' name='langue' value='<?php echo $langue; ?>' >
<input type='hidden' name='file' value='<?php echo $file; ?>' >

<div id="edittable">
<table class="editbook">
<?php
/**************************
affichage du resultat du parsing
**************************/

$point = $pointarray[$showpoint];
if (empty($lat)) { $lat = $point["lat"]; }
if (empty($lng)) { $lng = $point["long"]; }
printPoint($point["name"], $lat,$lng,$point["url"],$point["photos"], $point["trips"], $point);

function printPoint($destiName, $destiLat, $destiLng, $destiUrl, $destiPhotos, $trips, $destiArray) {
	global $index, $triparraySelect, $showtrip, $lang_destination_name, $lang_destination_url, $lang_destination_lat, $lang_destination_long, $lang_destination_trips;

        $urldomain = $url;

	$r = "\n";
	$r .= '<tr><td>'.$lang_destination_name.'</td><td >';
	$r .= " <input type='hidden' name='editName' value='".$destiName."' >\n";
	$r .= " <input type='text' name='editNewname' value='".$destiName."' >\n";
	$r .= "</td></tr>";
	$r .= '<tr><td>'.$lang_destination_url.'</td><td >';
	$r .= " <input type='text' name='editUrl' value='".urldecode($destiUrl)."' >\n";
	$r .= "</td></tr>";

	$r .= printPointPhoto($destiPhotos[0]['url']);

	$r .= '<tr><td>'.$lang_destination_trips.'</td><td >';

        if (empty($trips)) {
            $trips = $showtrip;
        }

	$r .= " <input type='text' name='editTags' value='".$trips."'  >\n";


	$r .= '<br/><select name="taglist" onchange="x=this.options[this.selectedIndex].value; if (x != \'\') {sep= \'; \'; if (this.form.editTags.value==\'\') {sep=\'\';} this.form.editTags.value+=sep+x;}">'.$triparraySelect.'</select>';
	$r .= "</td></tr>";
	
	$r .= printMoreInfo($destiArray);

	$r .= '<tr><td>'.$lang_destination_lat.'</td><td >';
	$r .= " <input type='text' name='editLat' value='".$destiLat."' >\n";
	$r .= "</td></tr>";
	$r .= '<tr><td>'.$lang_destination_long.'</td><td >';
	$r .= " <input type='text' name='editLng' value='".$destiLng."' >\n";
	$r .= "</td></tr>";

	print $r;
}

function printPointPhoto($photourl="") {
global $lang_destination_photourl;
	$r = "";
	        $r .= '<tr><td>'.$lang_destination_photourl.'</td><td >';
   	        $r .= "<input type='text' name='editPhotoUrl' value='".$photourl."'  >\n";
	        $r .= "</td></tr>";
		return $r;
}
function printMoreInfo($destiArray) {
global $moreinfoNames, $moreinfoNamesLabel;
	$r = "";
         foreach($moreinfoNames as $name) {
	        $r .= '<tr><td>'.$moreinfoNamesLabel[$name].'</td><td >';
   	        $r .= "<input type='text' name='".$name."' value='".$destiArray[$name]."' >\n";
	        $r .= "</td></tr>";
         }
		return $r;
}


?>
</form></table>
</div>
</body>
</html>
